<?php
session_start();
	
	$host="localhost";
	$username="root";
	$password="";
	$database="cs4400_group17";

	mysql_connect($host,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	
	$username = $_SESSION['userName'];
	$useremail = $_SESSION['userEmail'];
	
	$corkTitle = $_GET['corkTitle'];
	$ppURL = $_GET['ppURL'];
	$OEmail = $_GET['OwnerEmail'];
	
	$ppDT= $_GET['ppDT'];
	$ppD= $_GET['ppD'];
	
	//echo $corkTitle;
	echo $ppURL;
	//echo $OEmail;
	
	$sql = "SELECT * FROM userlikes WHERE PushPinTitle = '$corkTitle' AND OwnerEmail = '$OEmail' AND Email = '$useremail' AND PushPinURL = '$ppURL'";
	$result = mysql_query($sql);
	$rows = mysql_fetch_array($result);
	
	
	if($rows['Email'] == $useremail){
		print "removing";
		$query = "DELETE FROM userlikes WHERE PushPinTitle = '$corkTitle' AND OwnerEmail = '$OEmail' AND Email = '$useremail' AND PushPinURL = '$ppURL'";
		mysql_query($query);
	}
	else{
		print "ading";
		$query = "INSERT INTO userlikes VALUES('$useremail','$OEmail','$ppURL','$corkTitle')";
		mysql_query($query);
	}
	
	header("location:ReturnViewPushpin.php?pushpinEmail=$OEmail &pushpinTitle=$corkTitle &pushpinURL=$ppURL &pushpinDateTime=$ppDT &pushpinDescription=$ppD");
?>